// VBConversions Note: VB project level imports
using System.Data;
using DevExpress.XtraEditors.Controls;
using System.Diagnostics;
using System.Xml.Linq;
using DevExpress.XtraEditors.Repository;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.VisualBasic;
using System.Configuration;
using System.Collections;
using DevExpress.XtraEditors;
using System.Data.Sql;
using Microsoft.SqlServer;
using System.Windows.Forms;
using System;
using DevExpress.XtraReports;
using Microsoft.SqlServer.Management.Smo;
using DevExpress;
using System.Linq;
using System.IO;
// End of VB project level imports


namespace SCIEF.SysBFW.CommonExt
{
	namespace Base
	{
		/// <summary>
		/// This class is use to populate the context menu of our Grid, it's an item of the menu.
		/// </summary>
		/// <remarks></remarks>
		public class ActionOption
		{
			
			public ActionOption()
			{
			}
			public ActionOption(string optionGroup, string optionName, string optionTitle, EventHandler eventHandler, bool enabled, bool visible, string queryName = null)
			{
				this.OptionGroup = optionGroup;
				this.OptionName = optionName;
				this.OptionTitle = optionTitle;
				this.EventHandler = eventHandler;
				this.Enabled = enabled;
				this.Visible = visible;
				this.QueryName = queryName;
			}
			/// <summary>
			/// QueryName is use to hide or show the Option depending on the QueryName of the GridExt
			/// </summary>
			/// <value></value>
			/// <returns></returns>
			/// <remarks>In some control it Containe the Level number of the GridExtPL.</remarks>
			public string QueryName {get; set;}
			/// <summary>
			/// Procedure that will be call when the option is selected
			/// </summary>
			/// <value></value>
			/// <returns></returns>
			/// <remarks></remarks>
			public EventHandler EventHandler {get; set;}
			/// <summary>
			/// Option is Enabled or Disable in the menu
			/// </summary>
			/// <value></value>
			/// <returns></returns>
			/// <remarks></remarks>
			public bool Visible {get; set;}
			/// <summary>
			/// Option is Visible or not in the menu
			/// </summary>
			/// <value></value>
			/// <returns></returns>
			/// <remarks></remarks>
			public bool Enabled {get; set;}
			/// <summary>
			/// Name of the Option Group
			/// </summary>
			/// <value></value>
			/// <returns></returns>
			/// <remarks>Use to regroup in section</remarks>
			public string OptionGroup {get; set;}
			/// <summary>
			/// Name of the option/Command
			/// </summary>
			/// <value></value>
			/// <returns></returns>
			/// <remarks></remarks>
			public string OptionName {get; set;}
			/// <summary>
			/// Title display for the menu
			/// </summary>
			/// <value></value>
			/// <returns></returns>
			/// <remarks></remarks>
			public string OptionTitle {get; set;}
		}
		/// <summary>
		/// This collection is use to populate the context menu. GridExtPL is one of the control who use it.
		/// </summary>
		/// <remarks></remarks>
		public class ActionOptionList : System.Collections.Generic.List<ActionOption>
		{
			
			public void ApplySecurity()
			{
				DataView aControlprops = default(DataView);
				
				foreach (ActionOption action in this)
				{
					//Set
					aControlprops = (from oControl in AppManager.DataSubjectAccess.AsEnumerable() where oControl.Field<string>("ControlCD") == action.OptionName && oControl.Field<string>("Class") == "ACT" && oControl.Field<string>("Property") == "Visible"
					select oControl).AsDataView();
					
					if (aControlprops.Count == 1)
					{
						if (AppManager.ApplicationOption.DescriptionColumnIndex == 2)
						{
							action.OptionTitle = (string) (aControlprops[0].Row["ControlDescr_PRM"].ToString());
						}
						else if (AppManager.ApplicationOption.DescriptionColumnIndex == 3)
						{
							action.OptionTitle = (string) (aControlprops[0].Row["ControlDescr_ALT"].ToString());
						}
						//
						if (action.OptionTitle.IndexOf("<ExportToMasterDB>") > 0)
						{
							action.OptionTitle = action.OptionTitle.Replace("<ExportToMasterDB>", AppManager.ExportToMasterDB);
						}
						
						action.Visible = System.Convert.ToBoolean(aControlprops[0].Row["Value"].ToString());
					}
					
					
					aControlprops = (from oControl in AppManager.DataSubjectAccess.AsEnumerable() where oControl.Field<string>("ControlCD") == action.OptionName && oControl.Field<string>("Class") == "ACT" && oControl.Field<string>("Property") == "Enabled"
					select oControl).AsDataView();
					
					if (aControlprops.Count == 1)
					{
						action.Enabled = System.Convert.ToBoolean(aControlprops[0].Row["Value"].ToString());
					}
					
				}
			}
			
		}
		
	}
	
}
